from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()

driver.get("https://www.baidu.com")
# 截图只支持png格式,其他格式(jpg)会出错但也会执行（保存）,默认与py文件同路径，指定路径需文件夹
# save_screenshot()
driver.save_screenshot("E://截图/sava.png")
driver.get_screenshot_as_file("E://截图/file.png")
# 以下方法要手动写入保存文件
driver.get_screenshot_as_png()
with open("E://截图/png.png", "wb") as f:
    f.write(driver.get_screenshot_as_png())

# .decode()解码
driver.get_screenshot_as_base64()
with open("E://截图/base64.png", "wb") as f:
    f.write(base64.b64decode(driver.get_screenshot_as_base64()))

driver.quit()

